package com.qys.livesMall.app.user.controller.app;


import com.qys.livesMall.app.user.model.dto.app.AppUserBankDTO;
import com.qys.livesMall.app.user.model.entity.H2AppUserBank;
import com.qys.livesMall.app.user.service.IH2AppUserBankService;
import com.qys.livesMall.common.result.R;
import com.qys.livesMall.framework.utils.SecurityUtils;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 用户银行卡信息 前端控制器
 * </p>
 *
 * @author dp
 * @since 2023-04-27
 */
@RestController
@RequestMapping("/app/user/bank")
@Tag(name = "用户银行卡信息")
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class H2AppUserBankController {

    private final IH2AppUserBankService userBankService;

    @PostMapping("/binding/bank")
    @Operation(summary = "绑定银行信息")
    public R<Void> bindingBankInfo(@RequestBody AppUserBankDTO userBankDTO) {
        userBankDTO.setUserId(String.valueOf(SecurityUtils.getUserId()));
        userBankService.bindingBankInfo(userBankDTO);
        return R.ok();
    }

    @GetMapping({"/bank/{type}", "/bank/{type}/{usdtType}"})
    @Operation(summary = "查询银行卡信息")
    @Parameters({
            @Parameter(name = "type", description = "卡包类型(0银行卡,1USDT,2BIT)", required = true),
            @Parameter(name = "usdtType", description = "usdt类型", required = true),
    })
    public R<List<H2AppUserBank>> queryBankByType(@PathVariable Byte type, @PathVariable(required = false) String usdtType) {
        return R.ok(userBankService.queryBankByTypeAndUserId(type, SecurityUtils.getUserId(), usdtType));
    }

    @PostMapping("/delete/{id}")
    @Operation(summary = "删除银行信息")
    public R<Void> bindingBankInfo(@PathVariable String id) {
        userBankService.delete(id);
        return R.ok();
    }
}
